// ProjectSwitch.cpp : implementation file
//

#include "stdafx.h"
#include "Measure.h"
#include "ProjectSwitch.h"
#include "afxdialogex.h"


// CProjectSwitch dialog

IMPLEMENT_DYNAMIC(CProjectSwitch, CDialogEx)

CProjectSwitch::CProjectSwitch(CWnd* pParent, const CMeasureSolution &solution)
	: CDialogEx(CProjectSwitch::IDD, pParent)
  , solution_(solution)
{
  active_project_name_      = solution_.active_project_name().c_str();
  active_project_directory_ = solution_.active_project_directory().c_str();
  active_project_index_     = solution_.active_project_index();
}

CProjectSwitch::~CProjectSwitch()
{
}

void CProjectSwitch::DoDataExchange(CDataExchange* pDX)
{
  CDialogEx::DoDataExchange(pDX);
  DDX_Text(pDX, IDC_PROJECT_NAME, active_project_name_);
  DDV_MaxChars(pDX, active_project_name_, 256);
  DDX_Text(pDX, IDC_PROJECT_DIRECTORY, active_project_directory_);
  DDV_MaxChars(pDX, active_project_directory_, 256);
  DDX_Control(pDX, IDC_PROJECT_LIST, wnd_project_list_);
  DDX_LBIndex(pDX, IDC_PROJECT_LIST, active_project_index_);
  DDX_Control(pDX, IDOK, wnd_project_switch_);
}


BEGIN_MESSAGE_MAP(CProjectSwitch, CDialogEx)
  ON_LBN_SELCHANGE(IDC_PROJECT_LIST, &CProjectSwitch::OnProjectListSelChange)
END_MESSAGE_MAP()


// CProjectSwitch message handlers


BOOL CProjectSwitch::OnInitDialog()
{
  CDialogEx::OnInitDialog();

  for(int index=0; index<solution_.NumProjects(); ++index) {
    wnd_project_list_.AddString(solution_.project(index).name.c_str());
  }

  wnd_project_list_.SetCurSel(active_project_index_);
  wnd_project_switch_.EnableWindow(FALSE);

  return TRUE;
}


void CProjectSwitch::OnProjectListSelChange()
{
  int cur_sel = wnd_project_list_.GetCurSel();
  if (cur_sel == active_project_index_) {
    wnd_project_switch_.EnableWindow(FALSE);
  } else {
    wnd_project_switch_.EnableWindow(TRUE);
  }
}
